﻿using FarseerPhysics.Dynamics.Contacts;
using IcicleFramework.Collision;
using IcicleFramework.GameServices;
using IcicleFramework.Physics;

namespace IcicleFramework.Components.Physics
{
    public abstract class CollisionBehaviourComponent : BaseComponent, ICollisionBehaviourComponent
    {
        public CollisionBehaviourComponent()
        {}

        protected CollisionBehaviourComponent(CollisionBehaviourComponent old) 
            : base(old)
        {}

        public abstract void OnCollision(IPhysicsComponent source, IPhysicsComponent collided, Contact contact);

        public override void Initialize()
        {
            IPhysicsManager collisionManager = GameServiceManager.GetService<IPhysicsManager>();

            if (collisionManager != null && this.Parent != null)
                collisionManager.SubscribeCollisionEvent(this.Parent.GUID, OnCollision);

            base.Initialize();
        }
    }
}
